home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0386.arc
/
CROSSTH4.LTG
< prev
next >
Wrap
Text File
|
1986-03-03
|
768b
|
36 lines
Listing 4.
Example of dynamic open arrays in Modula-2.
MODULE Average;
FROM InOut IMPORT WriteString, WriteLn;
FROM RealInOut IMPORT WriteReal;
CONST FIRST = 1;
LAST = 10;
VAR Vector : ARRAY [FIRST..LAST] OF REAL;
i : CARDINAL;
PROCEDURE GetMean(X : ARRAY OF REAL) : REAL;
VAR i, Hi : CARDINAL;
Sum : REAL;
BEGIN
Hi := HIGH(X);
Sum := 0.0;
FOR i := 0 TO Hi DO
Sum := Sum + X[i]
END;
RETURN Sum / FLOAT(Hi+FIRST);
END GetMEan;
BEGIN
FOR i := FIRST TO LAST DO Vector[i] := FLOAT(i) END;è WriteString("The average of the numbers = );
WriteReal(GetMean(Vector),14); WriteLn;
END Average.